package basic;
//带参带返回值方法，即带有参数列表，返回值不为void的方法
public class MethodDemo4 {
    public int getSumOfSquares(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i * i;
        }
        return sum;
    }

    public static void main(String[] args) {
        MethodDemo4 methodDemo4 = new MethodDemo4();
        int getSumOfSquares =methodDemo4.getSumOfSquares(4);
        System.out.println("1到4的累加平方和为：" + getSumOfSquares);
        //也可以不定义变量接收返回结果，直接打印方法调用语句
        //System.out.println（"1到5的累加平方和为：" + methodDemo4.getSumOfSquares(5)）;

    }
}
